"""
首页利率查询模块
"""
import unittest
import requests
from cookie import login

base_header = {'cookie': login.Logins()}


class Rxd_LoanRat_Case(unittest.TestCase):

    def setUp(self):
        self.base_url = 'http://plsadmpre.cnsuning.com/plsadm/loan/test/qryLoanRate.do'

    def tearDown(self):
        print(self.result)

    def base_req(self, base_data, base_Checkpoint="status", base_Checkchar="01"):
        r = requests.post(url=self.base_url, data=base_data, headers=base_header)
        self.result = r.json()
        res = str(self.result)
        if len(res) > 50:
            """
            assertIn 判断是否包含, assertEqual 判断是否一致
            """
            # self.assertIn(str('"status":"01"'), res)
            result = eval(self.result['result'])
            self.assertEqual(result[base_Checkpoint], base_Checkchar)
        else:
            # self.assertIn("'result': '成功'", res)
            self.assertEqual(self.result['result'], '成功')

        return self.result

    # 参数正确，首页利率查询成功 """
    def test_loanrate_01(self):
        base_data = {'partnerNo': '10', 'intfNo': 'A016', 'productNo': 'RXD', 'custSource': '01',
                     'idNo': '520101198708150259'}
        base_Checkpoint = "status"
        base_Checkchar = "01"
        self.base_req(base_data, base_Checkpoint, base_Checkchar)

    # idNo为空，首页利率查询成功，loanRateList为空 """
    def test_loanrate_02(self):
        base_data = {'partnerNo': '10', 'intfNo': 'A016', 'productNo': 'RXD', 'custSource': '01', 'idNo': ''}
        base_Checkpoint = "loanRateList"
        base_Checkchar = []
        # noinspection PyTypeChecker
        self.base_req(base_data, base_Checkpoint, base_Checkchar)

    # partnerNo 为空，首页利率查询失败，系统异常，请稍后重试 """
    def test_loanrate_03(self):
        base_data = {'partnerNo': '', 'intfNo': 'A016', 'productNo': '', 'custSource': '01',
                     'idNo': '520101198708150259'}
        base_Checkpoint = "remark"
        base_Checkchar = "系统异常，请稍后重试"
        self.base_req(base_data, base_Checkpoint, base_Checkchar)

    # 不传 productNo，首页利率查询失败，remark 提示 productNo may not be null """
    def test_loanrate_04(self):
        base_data = {'partnerNo': '10', 'intfNo': 'A016', 'custSource': '01', 'idNo': '520101198708150259'}
        base_Checkpoint = "remark"
        base_Checkchar = "productNo may not be null"
        self.base_req(base_data, base_Checkpoint, base_Checkchar)

    # 不传 partnerNo，首页利率查询失败，remark 提示 partnerNo may not be null """
    def test_loanrate_05(self):
        base_data = {'intfNo': 'A016', 'productNo': '', 'custSource': '01', 'idNo': '520101198708150259'}
        base_Checkpoint = "remark"
        base_Checkchar = "partnerNo may not be null"
        self.base_req(base_data, base_Checkpoint, base_Checkchar)

    # 不传 custSource，首页利率查询失败，remark 提示 custSource may not be null """
    def test_loanrate_06(self):
        base_data = {'partnerNo': '10', 'intfNo': 'A016', 'productNo': 'RXD',
                     'idNo': '520101198708150259'}
        base_Checkpoint = "remark"
        base_Checkchar = "custSource may not be null"
        self.base_req(base_data, base_Checkpoint, base_Checkchar)

    # 不传 idNo，首页利率查询失败，remark 提示 idNo may not be null """
    def test_loanrate_07(self):
        base_data = {'partnerNo': '10', 'intfNo': 'A016', 'productNo': 'RXD', 'custSource': '01'}
        base_Checkpoint = "remark"
        base_Checkchar = "idNo may not be null"
        self.base_req(base_data, base_Checkpoint, base_Checkchar)


if __name__ == '__main__':
    unittest.main()
